#include "Includes.h"
#include "XorStr.h"
#include "dt_common2.h"


const char* DVariant::ToString()
{
	static char text[128];

	switch ( m_Type )
	{
	case DPT_Int : 
		sprintf_s( text, sizeof(text), /*%i*/XorStr(2, 0x49, 0x6CA10000).c_str(), m_Int );
		break;
	case DPT_Float :
		JUNK_CODE;
		sprintf_s( text, sizeof(text), /*%.3f*/XorStr(4, 0x7A, 0x5FD74B91).c_str(), m_Float );
		break;
	case DPT_Vector :
		sprintf_s( text, sizeof(text), /*(%.3f,%.3f,%.3f)*/XorStr(16, 0x4F, 0x67EB63FF, 0x2DE66CE6, 0x74A069E1, 0x6DF127E9).c_str(), 
			m_Vector[0], m_Vector[1], m_Vector[2] );
		break;
#if 0 // We can't ship this since it changes the size of DTVariant to be 20 bytes instead of 16 and that breaks MODs!!!
	case DPT_Quaternion :
		sprintf_s( text, sizeof(text), /*(%.3f,%.3f,%.3f %.3f)*/XorStr(21, 0x1E, 0x36B832A8, 0x7CB53DB9, 0x25F338B6, 0x3CA276AF, 0x2BA33FED, 0x23000000).c_str(), 
			m_Vector[0], m_Vector[1], m_Vector[2], m_Vector[3] );
		break;
#endif
	case DPT_String : 
		if ( m_pString ) 
			return m_pString;
		else
			return /*NULL*/XorStr(4, 0xEA, 0xA43CA42B).c_str();
		break;
	case DPT_Array :
		JUNK_CODE;
		sprintf_s( text, sizeof(text), /*Array*/XorStr(5, 0x7C, 0x3D890898, 0x01000000).c_str() ); 
		break;
	case DPT_DataTable :
		sprintf_s( text, sizeof(text), /*DataTable*/XorStr(9, 0x7F, 0x3B9F099D, 0x2F9B1B94, 0x12000000).c_str() ); 
		break;
	default :
		sprintf_s( text, sizeof(text), /*DVariant type %i unknown*/XorStr(24, 0x8F, 0xCB58EC7E, 0xE26BE77C, 0xA772FC74, 0xE622A469, 0x5F8B1397, 0x15950E96).c_str(), m_Type ); 
		break;
	}

	return text;
}

// This can be used to set the # of bits used to transmit a number between 0 and nMaxElements-1.
int NumBitsForCount( int nMaxElements )
{
	int nBits = 0;
	while ( nMaxElements > 0 )
	{
		++nBits;
		nMaxElements >>= 1;
	}
	return nBits;
}